package toanstt.com.MatchUp;


import toanstt.com.gameplay.G;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.RemoteViews.ActionException;

public class Notice
{
	int width;
	int height;
	
	int x,y;
	Button[] bottons;
	int n_button;
	Matrix mat;
	int type=0;
	int type2;
	public boolean doalpha = true;
	
	int TYPE_TIMETOUT = 0;
	int TYPE_FINISH = 1;
	int TYPE_YESNO = 2;
	
	String message="";
	
	int message_dx = (T.DISPLAY_WIDTH)/2;
	int message2_dx = (T.DISPLAY_WIDTH)/2;
	int i;
	int n;
	//Button but_replay,but_menu,but_next,but_yes,but_no;
	ButtonCenter[] buttons;
	final static public int FINISH = 0;
	final static public int QUIT = 1;
	final static public int REPLAY = 2;
	final static public int MENU = 3;
	
	public Notice()
	{
		type2 =0;
		x = T.DISPLAY_WIDTH/2;
		y = (int)(5*T.U2);
		n=3;
		buttons = new ButtonCenter[3];
		for(i =0;i<3;i++)
			buttons[i] = new ButtonCenter(T.TBITMAP_BUTTON_MENU.bitmap[0], T.DISPLAY_WIDTH/2, (int)((i+3)*4.2*T.U2));
		
	}
	int d;
	synchronized void  Draw(Canvas canvas)
	{
		if(T.THEME_WHITE)
		{
			if(type2 >0)
				canvas.drawARGB(220, 0, 0,0);
			else
			{
				canvas.drawARGB(230, 0, 0,0);
				//canvas.drawARGB(220, 255, 255, 255);
				//canvas.drawBitmap(T.TBITMAP_BANNER.bitmap[0], T.DISPLAY_WIDTH/2 - T.TBITMAP_BANNER.bitmap[0].getWidth()/2, 0, null);
			}
		}
		
		
		
		
		if(type2 >0)
		{
			//canvas.drawARGB(220, 0, 0, 0);
			canvas.drawBitmap(T.TBITMAP_STARS.bitmap[type2-1], T.DISPLAY_WIDTH/2 - T.TBITMAP_STARS.bitmap[type2-1].getWidth()/2, (int)(5*T.U2), null);
			T.bitmapfont.drawString(canvas,message,x,y-(int)(T.U2),2);
		}
		else
			T.bitmapfont.drawString(canvas,message,x,y,2);
		for(d=0;d<n;d++)
			buttons[d].Draw2(canvas);

	}
	int t;
	void toch(MotionEvent mo)
	{
//		for(t=0;t<n;t++)
//			if(buttons[t].Kick(mo) == true)
//			{
//				break;
//			}
		boolean isnext=false;
		switch (type)
		{
		case Notice.QUIT:
			if(buttons[0].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				T.onnotice = false;
				T.soundtheme.Stop();
				T.SaveInfo();
				MainActivity.activity.finish();
			}
			else if(buttons[1].Kick(mo) == true)
			{
				T.onnotice = false;
				T.sounds.Play(Sound2.BUTTON_CLICK);
			}
		break;
		case Notice.FINISH:
			if(buttons[0].Kick(mo) == true)
			{
				isnext=false;
				T.sounds.Play(Sound2.BUTTON_CLICK);
				T.onnotice = false;
				
				if(T.GAME_I1 == T.PLAYER_I1 && T.GAME_I2 == T.PLAYER_I2)
					isnext=true;
				T.GAME_I2 ++;
				if(T.GAME_I2 == 24)
				{
					T.GAME_I2 = 0;
					T.GAME_I1 ++;
					if(T.GAME_I1 == 4)
						T.GAME_I1 = 3;
				}
				if(isnext == true)
				{
					T.PLAYER_I1 = T.GAME_I1;
					T.PLAYER_I2 = T.GAME_I2;
				}
				//T.SCREEN = SCR.MENU;
				//G.savegame.SaveGame();
				//T.TOAST("Auto Saving !");
				//T.onnotice = false;
				//T.sounds.Play(Sound2.BUTTON_CLICK);
				if(T.SCREEN_TEMP == -1)
				{
					
					T.ALPHA =T.ALPHA_COUNT_MAX;
					T.GAMEPLAYMODE =2;
				}
				//G.NewGame(T.GAME_I1, T.GAME_I2);
				type2 =0;
			}
			else if(buttons[1].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				//G.NewGame(T.GAME_I1, T.GAME_I2);
				if(T.SCREEN_TEMP == -1)
				{
					
					T.ALPHA =T.ALPHA_COUNT_MAX;
					T.GAMEPLAYMODE =2;
				}
				//T.onnotice = false;
				type2 =0;
				if(T.GAME_I1 == T.PLAYER_I1 && T.GAME_I2 == T.PLAYER_I2)
				{
					T.PLAYER_I2 ++;
					if(T.PLAYER_I2 == 24)
					{
						T.PLAYER_I2 = 0;
						T.PLAYER_I1 ++;
						if(T.PLAYER_I1 == 4)
							T.PLAYER_I1 = 3;
					}
				}
				
			}
			else if(buttons[2].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				//T.SCREEN = SCR.MENU;
				//T.onnotice = false;
				if(T.SCREEN_TEMP == -1)
				{
					
					//T.SCREEN = SCR.MENU;
					///G.savegame.SaveGame();
					//T.TOAST("Auto Saving !");
					//T.onnotice = false;
					//T.sounds.Play(Sound2.BUTTON_CLICK);
					T.ALPHA =T.ALPHA_COUNT_MAX;
					T.SCREEN_TEMP = SCR.MENU;
				}
				type2 =0;
				if(T.GAME_I1 == T.PLAYER_I1 && T.GAME_I2 == T.PLAYER_I2)
				{
					T.PLAYER_I2 ++;
					if(T.PLAYER_I2 == 24)
					{
						T.PLAYER_I2 = 0;
						T.PLAYER_I1 ++;
						if(T.PLAYER_I1 == 4)
							T.PLAYER_I1 = 3;
					}
				}
			}
			T.SaveInfo();
		break;
		case Notice.MENU:
			if(buttons[0].Kick(mo) == true)
			{
				
				if(T.SCREEN_TEMP == -1)
				{
					
					//T.SCREEN = SCR.MENU;
					//G.savegame.SaveGame();
					//T.TOAST("Auto Saving !");
					//T.onnotice = false;
					T.sounds.Play(Sound2.BUTTON_CLICK);
					T.ALPHA =T.ALPHA_COUNT_MAX;
					T.SCREEN_TEMP = SCR.MENU;
				}
				App.ads.setTurnON();
			}
			else if(buttons[1].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				T.onnotice = false;
			}
		break;
		case Notice.REPLAY:
			if(buttons[0].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				//G.NewGame(T.GAME_I1, T.GAME_I2);
				//T.onnotice = false;
				if(T.SCREEN_TEMP == -1)
				{
					T.sounds.Play(Sound2.BUTTON_CLICK);
					T.ALPHA =T.ALPHA_COUNT_MAX;
					T.GAMEPLAYMODE =2;
				}
			}
			else if(buttons[1].Kick(mo) == true)
			{
				T.sounds.Play(Sound2.BUTTON_CLICK);
				T.onnotice = false;
			}
		break;
		}
		if(App.action == MotionEvent.ACTION_UP)
			ResetAllMouseAlpha();
	}
	int typeyesno=0;
	public void DoNotice(int type3,int typeyesno2)
	{
		type = type3;
		T.onnotice = true;
		if(type == Notice.FINISH)
		{
			type2 = typeyesno2;
			message = "FINISH";
			buttons[0].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[16];
			buttons[1].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[17];
			buttons[2].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[18];
			n=3;
		}
		else if(type == Notice.QUIT)
		{
			n=2;
			message = "EXIT?";
			buttons[0].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[14];
			buttons[1].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[15];
				
		}	
		else if(type == Notice.REPLAY)
		{
			n=2;
			message = "REPLAY?";
			buttons[0].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[14];
			buttons[1].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[15];
				
		}	
		else if(type == Notice.MENU)
		{
			n=2;
			message = "GO TO MENU?";
			buttons[0].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[14];
			buttons[1].bitmap = T.TBITMAP_BUTTON_MENU.bitmap[15];	
		}	
		ResetAllMouseAlpha();
	}
	public void ResetAllMouseAlpha()
	{
		for(int d2=0;d2<3;d2++)
			buttons[d2].anpla = 255;
	}
	public void SetMessages(String m1,String m2)
	{
		
	}
}

